new Object()
{}
屬性(key):值(value)
,每組以 ,
隔開.屬性
,但如果屬性是數字不適用["屬性"]
,不加 ""
會被當成變數,但如果屬性是數字不用 ""
物件種類與讀取例子
let obj = {
a : 1,
b : "string",
c : [2, 3],
d : function(){
console.log("d");
},
e :{
e1 : "1",
e2 : "2"
}
};
console.log(obj["c"]); // [2, 3]
console.log(obj.d()); // "d"
console.log(obj.e.e1); // "1"
delete
,刪除想要變更的屬性物件變更例子
let obj1 = new Object();
let obj2 ={};
obj1.a = "1";
obj1["b"] = 30;
console.log(obj1); // {a: '1', b: 30}
obj1.a = "a";
delete obj1.b;
console.log(obj1); // {a: 'a'}
預計再說明一下物件與陣列